Conversation
Add a testing modernization plan and migrate test layout and CI to the new approach. Remove the legacy Jest config and delete legacy __tests__ artifacts, add a new top-level test/ suite with helpers (including test/helpers/env.js) and route test files, and update docs and CI to run the consolidated npm script (allTests) and expose targeted scripts (coreTests, existsTests, functionalTests). Dev dependencies and package metadata were adjusted to support the new runner/coverage tools.
Introduce a GitHub Actions test matrix (fast and full gates) to run CI test groups. Add a Playwright-based browser smoke test (test/e2e/ui-smoke.test.js) that launches the app and verifies basic UI flows. Update README with local instructions for running e2e (install browsers) and the ci:fast/ci:full command groups.
Introduce launchBrowserOrSkip helper to centralize Chromium launch and skip logic when not installed, and refactor existing smoke test to use it. Add several end-to-end UI smoke tests: successful create submission (stubbing /create), client-side JSON validation that prevents network calls, query form results (stubbing /query), and overwrite conflict handling (stubbing /overwrite returning 409). Tests use Playwright routing to mock server responses and assert flash messages and object viewer output.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Capture fetch URL/options in test mocks and add assertions to verify the upstream RERUM contract (URL, HTTP method, Authorization header, Content-Type). Updates test/routes/{create,delete,overwrite,query,update}.test.js to record lastFetchUrl/lastFetchOptions and assert correct endpoint/method/headers, and documents the new validation in test/TESTING.md with an example and rationale to catch breaking changes.
Update test suites to accept application/ld+json by configuring express.json({ type: ['application/json', 'application/ld+json'] }) across create, query, delete, overwrite, and update tests. Add new tests: create and query now verify requests with Content-Type application/ld+json are accepted. Add tests that sending text/plain yields 415 in create, delete, overwrite, and update. Import and mount the error messenger in delete, overwrite, and update tests. Add network-failure cases that map rejected fetch to a 502 response for overwrite and update.
Add tests to exercise create route behavior: ensure request body id is converted to _id before upstream, and verify a successful upstream response missing id fields is treated as an error (502). Add new tests for verifyJsonContentType middleware to ensure it returns 415 when the Content-Type header is missing or when multiple Content-Type values are provided. These tests guard against regressions in id handling and content-type validation.
Add two tests to test/routes/error-messenger.test.js: one verifies the error messenger returns early when headers have already been sent (preserving partial response and leaving status 200), and another verifies that when an upstream error provides a text/plain Content-Type and a text() method, the messenger forwards the plain-text body and upstream status (example uses 418). These cover edge cases for header-sent behavior and handling of plain-text upstream responses.
Adds test/routes/rerum.test.js which verifies that fetchRerum maps fetch timeouts (AbortError) to a 504 upstream timeout error. The test mocks global.fetch to reject with an AbortError, sets RERUM_FETCH_TIMEOUT_MS to a low value, and asserts the returned error has status 504 and an appropriate message. Test setup/teardown restore the original global.fetch and environment variable.
Add a new test file for checkAccessToken (test/routes/tokens.test.js) to cover missing ACCESS_TOKEN, malformed JWTs, and refresh error propagation. Update error-messenger.test.js to assert statusCode/statusMessage fallback handling. Extend rerum.test.js to save/restore global setTimeout/clearTimeout and add tests that map non-timeout fetch failures to a 502 upstream error, ensure provided AbortSignal is forwarded, and verify fallback to the default timeout when the configured timeout is invalid.
Add unit tests for /query to cover upstream and network failure handling: (1) preserves upstream error text when fetch returns non-ok (503), (2) falls back to a generic RERUM error message when upstream .text() throws, and (3) maps rejected fetch (e.g., socket hang up) to a 502 response. Tests mock global.fetch and assert statusCode 502 and expected response text.
Add several unit tests to improve error handling coverage and token middleware behavior. create.test.js and overwrite.test.js gain tests that preserve upstream text on non-409 failures, fall back to a generic RERUM message when upstream .text() throws, and map missing-id successful payloads to 502. error-messenger.test.js replaces res.write with res.end in an existing test and introduces createMockRes plus focused messenger unit tests for headersSent, payload JSON, JSON content-type, and plain-text upstream errors. tokens.test.js adds tests ensuring valid or non-numeric-exp access tokens skip refresh. These changes increase robustness of error-path handling and token refresh logic in tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request significantly expands and improves the automated test coverage for the application's REST API routes and middleware, focusing on robust error handling, edge cases, and correct propagation of upstream errors. The new and updated tests ensure that the application behaves correctly under a wide variety of failure scenarios, including network errors, malformed requests, and upstream service issues.
Key changes include:
Error Handling and Propagation:
.text()methods throw. Also added checks for correct status codes when upstream payloads are missing required fields. [1] [2] [3] [4] [5]Middleware and Route Edge Cases:
verifyJsonContentTypemiddleware to ensure it returns appropriate errors when theContent-Typeheader is missing or contains multiple values.Upstream Communication and Timeout Handling:
fetchRerumutility to ensure correct handling of timeouts (mapping to 504), non-timeout network errors (mapping to 502), forwarding of abort signals, and fallback to default timeout when configuration is invalid.These improvements greatly increase confidence in the application's resilience and correctness in the face of both expected and unexpected error conditions.
Error Handling and Propagation:
Middleware and Route Edge Cases:
verifyJsonContentTypemiddleware to handle missing or multipleContent-Typeheaders.Upstream Communication and Timeout Handling:
fetchRerumtests for timeout mapping (504), network error mapping (502), abort signal forwarding, and default timeout fallback.